package otherWork;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;

/**
 * Created by lenovo on 2017/1/20.
 */
public class GetProperties {
    public static Map<String,String> getPro() {
        Properties prop = new Properties();
        Map<String,String> map = new HashMap<String, String>();
        try {
            System.out.println(System.getProperty("user.dir"));
            //读取属性文件a.properties
            InputStream in = new BufferedInputStream(new FileInputStream(System.getProperty("user.dir") + "\\src\\main\\resources\\properties\\modelName.properties"));
            prop.load(in);     ///加载属性列表
            Iterator<String> it = prop.stringPropertyNames().iterator();
            while (it.hasNext()) {
                String key = it.next();
                System.out.println(key + ":" + prop.getProperty(key));
                map.put(key,prop.getProperty(key));
            }
            in.close();

            ///保存属性到b.properties文件
            /*FileOutputStream oFile = new FileOutputStream("b.properties", true);//true表示追加打开
            prop.setProperty("phone", "10086");
            prop.store(oFile, "The New properties file");
            oFile.close();*/
        } catch (Exception e) {
            System.out.println(e);
        }
        return map;
    }

    public static void main(String [] args){
        getPro();
        System.out.println("哈哈");
    }
}
